<template>
  <view>
    <view class="publishContain defaultMain">
      <mypicturefeed ref="mypicture" type="detail" :album-list="takePicList">
        <view>反馈拍照</view>
      </mypicturefeed>
      <myvideofeed ref="myvideo" type="detail" :old-video-list="videoList">
        <view>反馈录像</view>
      </myvideofeed>
      <!-- 描述 -->
      <view class="desStyle">
        <view class="desLabel">
          <view style="margin-bottom: 26rpx;">反馈描述</view>
        </view>
        <view class="desContent">
          {{ fd_description }}
        </view>
      </view>
      <view class="desStyle">
        <view class="desLabel">
          <view style="margin-bottom: 26rpx;">审核结果</view>
        </view>
        <u-radio-group v-model="value" @change="radioGroupChange">
          <u-radio
            v-for="(item, index) in list"
            :key="index"
            :name="item.name"
            :disabled="item.disabled"
          >
            {{ item.name }}
          </u-radio>
        </u-radio-group>
      </view>
      <view class="desStyle" v-if="showFailReason">
        <view class="desLabel">
          <view style="margin-bottom: 26rpx;">驳回或审核失败原因</view>
        </view>
        <u-input
          v-model="fail_reason"
          :type="type"
          :border="border"
          width="750"
          height="150"
          :auto-height="autoHeight"
          :placeholder="placeholder"
        />
      </view>
      <!-- 驳回按钮 -->
      <view class="suishoupaiButton">
        <u-button
          type="primary"
          :ripple="true"
          ripple-bg-color="#74b9ff"
          @click="submitSuiShouPai"
          >审核提交</u-button
        >
      </view>
    </view>
  </view>
</template>
<script>
import mypicturefeed from "../picvideo/picture.vue";
import myvideofeed from "../picvideo/video.vue";
import { myAuditSubmit } from "../../../common/api/mine";
let that;
export default {
  name: "feedDetail",
  props: {
    content_id: {
      type: Number,
      default: 0,
    },
    fd_description: {
      type: String,
      default: "",
    },
    takePicList: {
      type: Array,
      default: [],
    },
    videoList: {
      type: Array,
      default: [],
    },
    feedBadgeNum: {
      type: Number
    },
    auditBadgeNum: {
      type: Number
    },
    finishedBadgeNum: {
      type: Number
    }
  },
  components: {
    mypicturefeed,
    myvideofeed,
  },
  mounted() {
    that = this;
    /* uni.pageScrollTo({
      //uni-app中页面滚动接口
      scrollTop: 1200, //滚动到页面的目标位置（单位px）
    }); */
  },
  data() {
    return {
      type: "textarea",
      border: true,
      width: 750,
      height: 150,
      autoHeight: true,
      list: [
        {
          name: "审核不通过",
          disabled: false,
        },
        {
          name: "审核通过",
          disabled: false,
        },
        {
          name: "驳回",
          disabled: false,
        },
      ],
      // u-radio-group的v-model绑定的值如果设置为某个radio的name，就会被默认选中
      value: "审核通过",
      showFailReason: false,
      audit_status: 1,
      placeholder: "",
      fail_reason: "",
    };
  },
  methods: {
    init() {
      // console.log('feedSubmit init----', this.takePicList, this.videoList)
      this.$refs.mypicture.$data.takePicList = this.takePicList;
      this.$refs.myvideo.$data.videoList = this.videoList;
    },
    // 选中任一radio时，由radio-group触发
    radioGroupChange(e) {
      // console.log("radioGroupChange---", e);
      switch (e) {
        case "审核不通过":
          that.audit_status = 0;
          that.showFailReason = true;
          that.placeholder = "请填写审核失败原因";
          uni.pageScrollTo({
            //uni-app中页面滚动接口
            scrollTop: 1200, //滚动到页面的目标位置（单位px）
          });
          break;
        case "审核通过":
          that.audit_status = 1;
          that.showFailReason = false;
          break;
        case "驳回":
          that.audit_status = 4;
          that.showFailReason = true;
          that.placeholder = "请填写驳回原因";
          uni.pageScrollTo({
            //uni-app中页面滚动接口
            scrollTop: 1200, //滚动到页面的目标位置（单位px）
          });
          break;

        default:
          break;
      }
    },
    submitSuiShouPai() {
      // 如果选择驳回或是不通过，原因必需填写
      if (!this.fail_reason && (that.audit_status === 0 || that.audit_status === 4)) {
        uni.showToast({
          title:
            that.audit_status === 4 ? "请填写驳回原因" : "请填写失败原因",
          icon: "error",
          mask: true,
        });
        return;
      }
      uni.showLoading({
        title: "提交中",
        mask: true,
      });
      // console.log("驳回");
      const Data = {
        content_id: that.content_id,
        audit_status: that.audit_status,
        fail_reason: that.fail_reason,
      };
      myAuditSubmit(Data).then((res) => {
        uni.hideLoading();
        uni.showToast({
          title: "审核已提交!",
          icon: "success",
          mask: true,
        });
        setTimeout(() => {
          uni.navigateBack({
              delta: 1
            });
          /* that.$Router.push({
            name: "myAudit",
            data: {
              allNeedFeed: this.feedBadgeNum,
              allNeedAudit: this.auditBadgeNum - 1,
              allFinished: this.finishedBadgeNum + 1,
            },
          }); */
        }, 1000);
      });
    },
  },
};
</script>
<style lang="scss" scoped>
.publishContain {
  padding: 0 0 170rpx;
  background-color: #fff;
}
.desStyle {
  padding: 20rpx;
  background-color: #fff;
  border-bottom: 1px solid #eee;
}
.desLabel {
  display: flex;
  justify-content: space-between;
}
.desContent {
  width: 100%;
  min-height: 300rpx;
  padding: 20rpx;
  border: 1rpx solid #eee;
  border-radius: 10rpx;
}
.suishoupaiButton {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 148rpx;
  box-sizing: border-box;
  padding: 0 30rpx;
  position: fixed;
  background-color: #ffffff;
  bottom: 0;
  text-align: center;
  box-shadow: 0 0 20px 0 rgba(0, 0, 0, 0.1);
  z-index: 999;
}
.suishoupaiButton u-button {
  width: 100%;
  border-radius: 10rpx;
}
</style>
